From 6ecc431c23ff284637c13bb6eccc39e114999fc6 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Wed, 14 May 2014 11:19:56 -0700 Subject: [PATCH] placessidebar: use proper canonicalization when checking if home Instead of just checking the string. This catches things like double slashes, relative paths and so on. https://bugzilla.gnome.org/show_bug.cgi?id=730142 --- gtk/gtkplacessidebar.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index da0f0197c5..2b6da81435 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -582,6 +582,28 @@ should_show_recent (GtkPlacesSidebar *sidebar) return recent_files_setting_is_enabled (sidebar) && recent_scheme_is_supported (); } +static gboolean +path_is_home_dir (const gchar *path) +{ + GFile *home_dir; + GFile *location; + const gchar *home_path; + gboolean res; + + home_path = g_get_home_dir (); + if (!home_path) + return FALSE; + + home_dir = g_file_new_for_path (home_path); + location = g_file_new_for_path (path); + res = g_file_equal (home_dir, location); + + g_object_unref (home_dir); + g_object_unref (location); + + return res; +} + static void add_special_dirs (GtkPlacesSidebar *sidebar) { @@ -608,7 +630,7 @@ add_special_dirs (GtkPlacesSidebar *sidebar) * to be added multiple times in that weird configuration. */ if (path == NULL || - g_strcmp0 (path, g_get_home_dir ()) == 0 || + path_is_home_dir (path) || g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0) != NULL) continue; @@ -662,7 +684,7 @@ get_desktop_directory_uri (void) /* "To disable a directory, point it to the homedir." * See http://freedesktop.org/wiki/Software/xdg-user-dirs */ - if (g_strcmp0 (name, g_get_home_dir ()) == 0) + if (path_is_home_dir (name)) return NULL; return g_strconcat ("file://", name, NULL); -- 2.30.2